package com.gosophia.taskManagement.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseAjaxAction;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.gosophia.taskManagement.dto.JobDTO;
import com.gosophia.taskManagement.ws.TaskManagementWebService;
import com.gosophia.userManagement.ws.UserManagementWebService;

/**
 * 获取待办列表
 * 
 * @author mayue
 * 
 */
@Controller("GetToDoMissionListAction")
@Scope("prototype")
public class GetToDoMissionListAction extends BaseAjaxAction<JobDTO> {

    // 简单查询和高级查询
    @Autowired
    private TaskManagementWebService taskManagementWebService;

    @Autowired
    private UserManagementWebService userManagementWebService;

    private static final long serialVersionUID = 1L;

    @Override
    public String _execute() throws Exception {
        // 用户详细信息id

        UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
                .getContext().getAuthentication().getPrincipal();
        Long myUserInfoId = userDetails.getUserAccountDTO().getUserInfoDTO()
                .getUserInfoId();

        if (this.searchType == true) {
            page = taskManagementWebService.findAllMyTodoJobByPage(
                    myUserInfoId, page.getPageSize(), page.getPageNo(),
                    propertyFilters, orderConditions);
        } else if (this.searchType == false) {
            if (searchString != null && !"".equals(searchString)) {
                searchString = searchString.trim();
            }
            page = taskManagementWebService.findAllMyTodoJobByPage(
                    myUserInfoId, searchString, page.getPageSize(), page
                            .getPageNo(), orderConditions, null);
        }

        if (page.getResult().size() == 0) {
            super.getRequestResult().setRsltCode("1");
        } else {
            // for(JobDTO jobDto : page.getResult()){
            // String jobType = jobDto.getJobType();
            // if("simulate".equalsIgnoreCase(jobType)){
            // jobDto.setJobType("已创建");
            // }else if("getBack".equalsIgnoreCase(jobType)){
            // jobDto.setJobType("文档审批取回");
            // }else if("approve".equalsIgnoreCase(jobType)){
            // jobDto.setJobType("文档审批");
            // }else if("modify".equalsIgnoreCase(jobType)){
            // jobDto.setJobType("文档修改");
            // }else if("documentFinalize".equals(jobType)){
            // jobDto.setJobType("文档定稿");
            // }
            // }
            super.getRequestResult().setRsltCode("0");
        }
        return SUCCESS;
    }

    @Override
    public JobDTO getDetailData() {
        // TODO Auto-generated method stub
        return null;
    }

}
